﻿@model VVA.Website.UI.Areas.Admin.Models.Account.ChangePasswordModel

@{
    ViewBag.Title = "ChangePassword";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

<div class="content-box">
    <div class="content-box-header">
        <h3>@ViewBag.Title</h3>
    </div>
    <div class="content-box-content">
        <form id="frmChangePassword">            
            <fieldset>
                <p>
                    @Html.LabelFor(model => model.OldPassword)
                    @Html.PasswordFor(model => model.OldPassword, new { @class = "text-input medium-input" })
                    @Html.ValidationMessageFor(model => model.OldPassword)
                </p>
                <p>
                    @Html.LabelFor(model => model.NewPassword)
                    @Html.PasswordFor(model => model.NewPassword, new { @class = "text-input medium-input" })
                    @Html.ValidationMessageFor(model => model.NewPassword)
                </p>
                <p>
                    @Html.LabelFor(model => model.ConfirmPassword)
                    @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "text-input medium-input" })
                    @Html.ValidationMessageFor(model => model.ConfirmPassword)
                </p>
                <p>
                    <a class="button" id="btnChangePassword">Đổi mật khẩu</a>
                    <a class="button" id="btnCancelChangePassword" href="@Url.Action("Index", "Dashboard")">Hủy bỏ</a>
                </p>
            </fieldset>
            <script type="text/javascript">
                $(document).ready(function () {
                    $("#frmChangePassword").validate();
                    $("#btnChangePassword").live("click", function () {
                        if ($("#frmChangePassword").valid()) {
                            var model = {
                                OldPassword: $("#OldPassword").val(),
                                NewPassword: $("#NewPassword").val(),
                                ConfirmPassword: $("#ConfirmPassword").val()
                            };
                            $.ajax({
                                type: "POST",
                                data: model,
                                url: "@Url.Action("ChangePassword", "Account")",
                                success: function (result) {
                                    if (result) {
                                        alert("Đổi mật khẩu thành công.");
                                    } else {
                                        alert("Đổi mật khẩu thất bại xin vui lòng kiểm tra lại.");
                                    }
                                }
                            });
                        }
                    });
                });
            </script>
        </form>
    </div>
</div>
